using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using BANSACH.BusinessLayer.DataLayer;
using BANSACH.BusinessLayer;
namespace BANSACH_GUI
{
    public partial class frmTblSACHDm : FormBase
    {
        DataView data;
        TblSACHFactory objDao;
        TblSACH _entity;

        public TblSACH Entity
        {
            get { return _entity; }
            set { _entity = value; }
        }
        public frmTblSACHDm()
        {
            InitializeComponent();
        }

        private void frmTblSACHDm_Load(object sender, EventArgs e)
        {
            ConfigGrid();

            objDao = new TblSACHFactory();
            data = objDao.GetAll().DefaultView;
            grvData.DataSource = data;
        }
        private void ConfigGrid()
        {
            grvData.ModeColorRow = 1;
            grvData.SetColorRow(System.Drawing.Color.AliceBlue);

            
				grvData.AddColumns("TextBox","MaSach","MaSach",200,true,true,"ML","");
				grvData.AddColumns("TextBox","TenSach","TenSach",200,true,true,"ML","");
				grvData.AddColumns("TextBox","TacGia","TacGia",200,true,true,"ML","");
				grvData.AddColumns("TextBox","MaNXB","MaNXB",200,true,true,"ML","");
				grvData.AddColumns("TextBox","NamXB","NamXB",200,true,true,"ML","");
				grvData.AddColumns("TextBox","MaTL","MaTL",200,true,true,"ML","");
				grvData.AddColumns("TextBox","TomTat","TomTat",200,true,true,"ML","");
				grvData.AddColumns("TextBox","UrlAnh","UrlAnh",200,true,true,"ML","");
				grvData.AddColumns("TextBox","GiaBia","GiaBia",200,true,true,"ML","");
				grvData.AddColumns("TextBox","GiaBan","GiaBan",200,true,true,"ML","");
				grvData.AddColumns("TextBox","NgayKK","NgayKK",200,true,true,"ML","");
				grvData.AddColumns("TextBox","SoluongKK","SoluongKK",200,true,true,"ML","");
				grvData.AddColumns("TextBox","Soluong","Soluong",200,true,true,"ML","");
        }
        private void SetDataFilter()
        {
            try
            {
                StringBuilder filter = new StringBuilder("1=1");
                data.RowFilter = filter.ToString();
            }
            catch
            { }
        }

        private void grvData_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (char.IsLetter(e.KeyChar))
                ActiveControl = txt_Key;
        }

        private void grvData_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            Apply();
        }

        private void grvData_KeyDown(object sender, KeyEventArgs e)
        {
            if(e.KeyCode == Keys.Enter)
                Apply();
            if (e.Control)
                ActiveControl = grvData;
        }
        private void Apply()
        {
            _entity = new TblSACH();
            if (grvData.SelectedCells.Count == 0) return;
            int idrow = grvData.SelectedCells[0].RowIndex;
            this.DialogResult = DialogResult.OK;
        }
    }
}
